define([
        "jquery",
        "model/SlideObj",
        "view/ThumbnailView",
        'lib/snap.svg'
], function($, SlideObj, ThumbnailView, Snap){

	function ThumbnailController(slideList) {
		
		this.thumbnailView = new ThumbnailView();
		this.mainController;
		this.slideList = slideList;
		this.pageNum = 0;
		
		this.slideSVG = null;
		this.selectedShape = null;
		
		
	
	};
	
	ThumbnailController.prototype = {
			
		setSlideList : function(slideList) {
			this.slideList = slideList;
		},
		
		setMainController : function(mainController) {
			this.mainController = mainController;
			this.thumbnailView.setController(this.mainController);
		},
			
		callRender : function() {//start
			this.slideList.push(new SlideObj());			
			this.pageNum++;
			this.mainController.currentSlideNum = this.pageNum;
			this.thumbnailView.doRender(this.slideList,this.pageNum);
		},
	
		addSlide : function() {
			
		
			this.slideList.push(new SlideObj()); 
			this.pageNum++;
			
			var slideEditorController = this.mainController.getSlideEditorController();
			
			if(this.mainController.currentSlideNum != null) { 
			
				this.thumbnailView.removeBoundary(this.mainController.currentSlideNum);
				slideEditorController.deleteWorkSpaceSlide(this.mainController.currentSlideNum); //�댁쟾 currentSlideNum���묒뾽�щ씪�대뱶 吏�슦湲�
			}
			
			this.mainController.currentSlideNum = this.pageNum;
			
		
			
			this.thumbnailView.addSlideToShow(this.pageNum);		
			
			
			slideEditorController.drawWorkSpaceSlide();
		},
		
		removeSlide : function() {
			var slideEditorController = this.mainController.getSlideEditorController();
			slideEditorController.deleteWorkSpaceSlide();
			
			var selectedSlideIndex = this.mainController.currentSlideNum-1;
			this.slideList[selectedSlideIndex] = null; 
			this.slideList = this.slideList.filter(function(x) { return x!=null;}); 
			
			slideEditorController.setSlideList(this.slideList);			
			$('#thumbNailSvg').children('.thumbNail_slide')[selectedSlideIndex].remove();  //썸네일 지움
			
			if(this.mainController.currentSlideNum == this.pageNum) { //delete last slide
				
				this.mainController.currentSlideNum = this.pageNum-1;
				
			} else { 
				var newSlideNum = this.mainController.currentSlideNum;
				var thumbNailSlide_y = 0;
				var thumbNailText_y = 0;
			
				for(var i=this.mainController.currentSlideNum-1; i<this.pageNum-1; i++) {
					thumbNailSlide_y = $('#thumbNailSvg').children('.thumbNail_slide').eq(i).children().eq(0).attr("y");
					thumbNailText_y = $('#thumbNailSvg').children('.thumbNail_slide').eq(i).children().eq(1).attr("y");
					
					$('#thumbNailSvg').children('.thumbNail_slide').eq(i).children().eq(0).attr({"id" : "slide"+newSlideNum});
					$('#thumbNailSvg').children('.thumbNail_slide').eq(i).children().eq(0).attr({"y" : thumbNailSlide_y-100});
					
					$('#thumbNailSvg').children('.thumbNail_slide').eq(i).children().eq(1).text(newSlideNum);
					$('#thumbNailSvg').children('.thumbNail_slide').eq(i).children().eq(1).attr({"y" : thumbNailText_y-100});
					
					$('#thumbNailSvg').children('.thumbNail_slide').eq(i).children().eq(2).attr({
						"transform" : "translate(46.5,"+ (10+(i)*100)+") scale(0.09)"
					});
					newSlideNum++;
					
				}
				
			}
			this.pageNum--; 
			this.thumbnailView.displayBoundary(this.mainController.currentSlideNum); //view���쒖떆
			slideEditorController.drawWorkSpaceSlide();
		},
		
		clickThumbNailSlide : function(e) {
			
			var textValue = e.target.id;
			var slideNumber = textValue.split("e");
			var slideEditorController = this.mainController.getSlideEditorController();
			
			if(this.mainController.currentSlideNum != null) {
				console.log("currentSlideNum !=null ",this.mainController.currentSlideNum);
				this.thumbnailView.removeBoundary(this.mainController.currentSlideNum);
				slideEditorController.deleteWorkSpaceSlide(this.mainController.currentSlideNum);
				
			}
			
			this.mainController.currentSlideNum = slideNumber[1]; 
			this.thumbnailView.displayBoundary(this.mainController.currentSlideNum);
			
			slideEditorController.drawWorkSpaceSlide();
		},
		
		sortSlideList : function() {
			
		},
		
		reflectThumbnail : function(slide_svg_children) {
			
			$('#thumbNailSvg').children('.thumbNail_slide').eq(this.mainController.currentSlideNum-1).children().eq(2).children().remove();
			this.thumbnailView.reflectThumbnail(slide_svg_children);
		}
	};
	
	return ThumbnailController;

});